package com.bsj.travel.system.controller;

import com.bsj.travel.def.common.DTO.web.menu.MenuDTO;
import com.bsj.travel.def.common.DTO.web.menu.MenuSearchDTO;
import com.bsj.travel.def.common.VO.MenuTreeVO;
import com.bsj.travel.def.common.VO.MenuVO;
import com.bsj.travel.def.global.JsonResult;
import com.bsj.travel.security.annotation.RequiresPermissions;
import com.bsj.travel.system.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/***
 * @description MenuController
 * @author LiJiaXin
 * @version 1.0.0
 * @time 2024/1/12 15:44
 **/
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 添加权限
     *
     * @param menuDTO
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/1/12 15:48
     */
    @PostMapping("/add")
    @RequiresPermissions(value = "menu:operation:add")
    public JsonResult add(@Validated MenuDTO menuDTO) {
        return menuService.addMenu(menuDTO);
    }

    /**
     * 删除权限
     *
     * @param id
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/1/12 16:29
     */
    @PostMapping("/delete/{id}")
    @RequiresPermissions(value = "menu:operation:delete")
    public JsonResult delete(@PathVariable("id") Integer id) {
        return menuService.deleteMenu(id);
    }


    /**
     * 修改权限
     *
     * @param menuDTO
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/1/12 16:30
     */
    @PostMapping("/update")
    @RequiresPermissions(value = "menu:operation:update")
    public JsonResult update(@Validated MenuDTO menuDTO) {
        return menuService.updateMenu(menuDTO);
    }

    /**
     * 根据权限id获取权限信息
     *
     * @param id
     * @return com.bsj.travel.def.global.JsonResult<com.bsj.travel.def.common.VO.MenuVO>
     * @author ljx
     * @time 2024/1/12 16:30
     */
    @GetMapping("/getById/{id}")
    @RequiresPermissions(value = "menu:info:getById")
    public JsonResult<MenuVO> getById(@PathVariable("id") Integer id) {
        return JsonResult.success(menuService.getMenuInfoById(id));
    }

    /**
     * 权限分页
     *
     * @param menuSearchDTO
     * @return com.bsj.travel.def.global.JsonResult<java.util.List < com.bsj.travel.def.common.VO.MenuVO>>
     * @author ljx
     * @time 2024/1/12 16:34
     */
    @GetMapping("/page")
    @RequiresPermissions(value = "menu:info:page")
    public JsonResult<List<MenuVO>> page(@Validated MenuSearchDTO menuSearchDTO) {
        return menuService.pageMenu(menuSearchDTO);
    }

    /**
     * 权限树
     *
     * @param
     * @return com.bsj.travel.def.global.JsonResult<java.util.List<com.bsj.travel.def.common.VO.MenuTreeVO>>
     * @author ljx
     * @time 2024/1/18 16:44
     */
    @GetMapping("/tree")
    @RequiresPermissions(value = "menu:info:tree")
    public JsonResult<List<MenuTreeVO>> tree() {
        return JsonResult.success(menuService.getMenuTree());
    }

}
